package com.samuel.controller;

import com.samuel.entities.CommonResult;
import com.samuel.entities.Payment;
import com.samuel.service.PaymentService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author a neng huang
 * @since 2021-02-24 21:44
 */
@Log4j2
@RestController
@RequestMapping("payment/api")
public class PaymentController {


    @Resource
    private PaymentService paymentService;

    @Value("${server.port}")
    private String port;

    @GetMapping("get/{id}")
    public CommonResult<Payment> get(@PathVariable("id") String id) {
        log.info("当前的端口号是：{}", port);
        return new CommonResult<>(200, "获取成功！", paymentService.getById(id));
    }

    @GetMapping("list")
    public CommonResult<List<Payment>> list() {
        log.info("当前的端口号是：{}", port);
        List<Payment> all = paymentService.getAll();
        return new CommonResult<>(200, "获取成功！", all);
    }

    @PostMapping("save")
    public CommonResult<Integer> save(@RequestBody Payment payment) {
        log.info("当前的端口号是：{}", port);
        int num = paymentService.create(payment);
        return new CommonResult<>(200, "保存成功！", num);
    }
}
